package com.sourny;

/**
 * @author sourny.yang
 * @date 2018/3/1 17:14
 */
public class UserFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
        // 从request中获取已校验成功的user
        User user = tryGetAuthenticatedUser(request, response);
        // 把user绑定到ThreadLocal
        // 在service中直接使用UserContext.getCurrentUser()获取user
        try (UserContext context = new UserContext(user)) {
            chain.doFilter(request, response);
        }
    }
}
